use crate::handlers as serve;
/// 在这里注册路由表
use crate::routes::handler::Handlers;
use std::collections::HashMap;

/// 路由表构建器
struct RouterBuilder {
    routes: HashMap<&'static str, Handlers>,
}

impl RouterBuilder {
    fn new() -> Self {
        Self {
            routes: HashMap::new(),
        }
    }

    /// 添加路由
    fn add_route(mut self, path: &'static str, handler: Handlers) -> Self {
        self.routes.insert(path, handler);
        self
    }

    /// 构建最终路由表
    fn build(self) -> HashMap<&'static str, Handlers> {
        self.routes
    }
}

lazy_static::lazy_static! {
    pub static ref ROUTES: HashMap<&'static str, Handlers> = {
        RouterBuilder::new()
            .add_route("project/create", serve::project::CreateProject.into())
            .add_route("project/all", serve::project::QueryProject.into())
            .add_route("project/load", serve::project::LoadProject.into())
            .add_route("project/import", serve::project::ImportProject.into())
            .add_route("ds/file/create", serve::datasource::CreateDsFile.into())
            .add_route("ds/serve/create", serve::datasource::CreateDsServe.into())
            .add_route("ds/list", serve::datasource::ListDatasource.into())
            .add_route("ds/load", serve::duck::LoadDatasource.into())
            .add_route("ds/table/all", serve::duck::TableAll.into())
            .add_route("ai/config/create", serve::ai::CreateAiConfig.into())
            .add_route("ai/config/list", serve::ai::ListAiConfig.into())
            .add_route("ai/config/update", serve::ai::UpdateAiConfig.into())
            .add_route("ai/config/delete", serve::ai::DeleteAiConfig.into())
            .add_route("ai/config/set-current", serve::ai::SetCurrentAiConfig.into())
            .add_route("ai/config/current-use", serve::ai::CurrentUseAiConfig.into())
            .add_route("ds/description/all", serve::datasource::AllDsDesc.into())
            .add_route("ds/description/create", serve::datasource::CreateDsDesc.into())
            .build()
    };
}
